<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\Request;

/**
 * 用户异常  不记录日志文件(app/Exceptions/Handler.php中配置)
 * Class InvalidRequestException
 *
 * @package App\Exceptions
 */
class InvalidRequestException extends Exception
{
    public function __construct( string $message="" , int $code=400 )
    {
        parent::__construct( $message , $code );
    }

    public function render( Request $request )
    {
        if( $request->expectsJson() ){
            //ajax请求
            return response()->json( [ 'msg'=>$this->message ] , $this->code );
        }

        return view( 'pages.errors' , [ 'msg'=>$this->message ] );
    }
}
